<template>
<div class="container-cc">
    <div v-for="(item, index) of pointList" :key="index" @click="toDetail(item.giftId)" class="box">
      <img class="mess-image" :src="item.image" alt="">
      <div class="title ellipsis-multiline">{{ item.title }}</div>
      <div class="item-msg">
        <div class="score">{{ item.score }}
          <span class="jfen">积分</span>
        </div>
      </div>
    </div>
    <div v-if="!loadingiconFlag" class="empty">没有更多了</div>
    <div class="loading-container" v-if="loadingiconFlag">
      <van-loading color="#1989fa" type="spinner">加载中...</van-loading>
    </div>
</div>
  <!-- <div class="no-data">
    <p class="text text1">阅读礼品，正在备货；</p>
    <p class="text text2">积分兑换，容后开放。</p>
  </div> -->
</template>
 
<script setup>
import { ref } from 'vue';
import { reactive } from 'vue';
import { useRouter } from 'vue-router';
import { onMounted } from 'vue'
import { getPointList } from '@/api/message';
import { showToast } from 'vant';
const loadingiconFlag = ref(false);
const router = useRouter()
const column = ref(2);
const pointList = ref([]);

const getList = () => {
  loadingiconFlag.value = true
    const params = {
      currentPage: 1,
      pageSize: 500,
      sidx: "issueTime",
      sort: "desc",
    }
    getPointList(params).then((res) => {
    if (res.code === 200) {
      if(res.data.list.length!=0){
          pointList.value = res.data.list
          pointList.value.map(s => {
            if(JSON.parse(s.coverImage).length){
              s.image = process.env.VITE_API_API_IMAGE_URL + JSON.parse(s.coverImage)[0].url
            }
          return s
        })
      }else{
        pointList.value = []
      }
    loadingiconFlag.value = false
    } else {
      showToast(res.msg)
      loadingiconFlag.value = false
    }
  }).catch((err) => {
    console.log(err)
  })
}

onMounted(() => {
  getList()
})

const toDetail = (id)=> {
  router.push({ path: '/GiftDetail',query: { id: id } })
}

</script>

<style lang="scss" scoped>
.no-data {
  display: flex;
  height: 100%;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  box-sizing: border-box;
  font-size: 2rem;

  .text {
    padding: 0;
    margin: 0;
  }
}





.container-cc {
  // background: #f9f9f9;
  overflow: hidden;
  padding: 1rem 1.4rem;
  box-sizing: border-box;
}
.box{
  margin-bottom: 2rem;
  border-radius: 1rem;
  box-sizing: border-box;
  background: #fff;
  padding: 1rem;
  width: 46%;
  display: inline-block;
}
.box:nth-child(2n+1) {
  margin-right: 8%;
}

.mess-image{
  width: 100%;
  aspect-ratio: 1/1;
  border-radius: .8rem;
}

.ellipsis-multiline {
  word-break: break-all;
  overflow: hidden;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}

.title {
  font-size: 1.4rem;
  margin-bottom: 0.4rem;
}


.item-msg {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: .6rem;
  color: #aaa;
  font-size: 1.2rem;
}
.time{
  margin-top: 0.2rem;
}
.score{
  color: red;
  font-size: 1.8rem;
}

.jfen{
  font-size: 1.2rem;
  color: #999;
}

.loading-container {
  display: flex;
  justify-content: center;
  align-items: center;
  height: 80vh;
}

.loading-container {
  display: flex;
  justify-content: center;
  align-items: center;
  height: 30rem;
}
.empty{
  color: #969799;
  font-size: 1.4rem;
  line-height: 5rem;
  text-align: center;
}
</style>